package com.rizzo.android.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.rizzo.android.R;

/**
 * Created with IntelliJ IDEA.
 * User: jalie
 * Date: 12/28/12
 * Time: 11:34 AM
 * To change this template use File | Settings | File Templates.
 */
public abstract class RizzoFragment extends Fragment {

    public static final String SHADOW_ALPHA_STATE = "shadowAlphaState";
    public static final String POSITION_STATE = "positionState";

    private float shadowAlpha = 0;
    private int position = -1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.rizzo_fragment_layout, null);
        Log.d(this.getClass().getCanonicalName(), "onCreateView");
        return inflate;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (savedInstanceState != null) {
            shadowAlpha = savedInstanceState.getFloat(SHADOW_ALPHA_STATE);
        }
        int pos = getArguments().getInt(POSITION_STATE);
        if (this.position == -1) {
            this.position = pos;
        }
        ImageView shadowView = (ImageView) view.findViewById(R.id.shadow);
        if (shadowView != null) {
            shadowView.setAlpha(shadowAlpha);
            shadowView.setTag("shadow-" + position);
        }
        Log.d(this.getClass().getCanonicalName(), "onViewCreated");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d(this.getClass().getCanonicalName(), "onActivityCreated");
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(POSITION_STATE, position);
        outState.putFloat(SHADOW_ALPHA_STATE, shadowAlpha);
    }

}
